package fire;
/**
 * Friendly Interactive Recursion Educator (FIRE)
 * COMS 4115: Programming Languages & Translators
 * Prof. Aho
 * 
 * @author Brian Lu
 * @author Sahar Hasan
 * @author Steve Hehl
 * @author Tristan Naumann
 * @version 2009-05-12
 */
import org.antlr.runtime.*;

public class LexTokens {
	public static void main(String[] args) {
		try {
			//ANTLRFileStream in = new ANTLRFileStream("C:\\Documents and Settings\\Tristan\\My Documents\\workspace\\test\\src\\in.test");
			ANTLRInputStream in = new ANTLRInputStream(System.in);
			FireLexer lexer = new FireLexer(in);
			WSFilter filter = new WSFilter(lexer);
			CommonTokenStream tokens = new CommonTokenStream(filter);
			tokens.discardOffChannelTokens(false);
			for (Object o : tokens.getTokens()) {
				Token t = (Token)o;
				System.out.print("<" 
						//+ "(" + t.getLine() + "," + t.getCharPositionInLine() + ")," 
						+ FireParser.tokenNames[t.getType()] + ","
						+ escape(t.getText())+ ","
						+ t.getChannel()
						+ "> ");
				if (t.getType() == FireLexer.NEWLINE)
					System.out.println();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static String escape (String s) {
		StringBuffer r = new StringBuffer();
		for (int i = 0; i < s.length(); i++)
			if (s.charAt(i) == '\n') r.append("\\n");
			else if (s.charAt(i) == '\r') r.append("\\r");
			else r.append(s.charAt(i));
		return r.toString();
	}
}